<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

require 'AliyunClient.class.php';
require 'PingAliyun.php';
require 'BasicConfig.php';

class UpdateDomainRecord extends AliyunClient {

    public function execute($RecordId, $RR, $Type, $Value, $TTL = null, $Priority = null, $Line = null) {


        $PublicParams["RecordId"] = (string) $RecordId;
        $PublicParams["RR"] = (string) $RR;
        $PublicParams["Type"] = (string) $Type;
        $PublicParams["Value"] = (string) $Value;

        if (isset($TTL)) {
            $PublicParams["TTL"] = (int) $TTL;
        }
        if (isset($Priority)) {
            $PublicParams["Priority"] = (int) $Priority;
        }
        if (isset($Line)) {
            $PublicParams["Line"] = (string) $Line;
        }

        $PublicParams["RecordId"] = $RecordId;
        $PublicParams["AccessKeyId"] = $this->accessKeyId;
        $PublicParams["Format"] = self::FORMAT;
        $PublicParams["SignatureMethod"] = self::SIGNATUREMETHOD;
        $PublicParams["SignatureVersion"] = self::SIGNATUREVERSION;
        $PublicParams["SignatureNonce"] = $this->CreateSignatureNonce();
        date_default_timezone_set("UTC");
        $PublicParams["TimeStamp"] = date(self::DATETIMEFORMAT);
        $PublicParams["Version"] = self::VERSION;
        $PublicParams["Action"] = $this->Action;
        $PublicParams["RecordId"] = $RecordId;

        $PublicParams["Signature"] = $this->computeSignature($PublicParams, $this->accessKeySecret);
        $requestUrl = rtrim(self::SERVERURL, "/") . "/?";
        foreach ($PublicParams as $ParamKey => $ParamValue) {
            $requestUrl .= "$ParamKey=" . urlencode($ParamValue) . "&";
        }
        $requestUrl = substr($requestUrl, 0, -1);
        return (string) $requestUrl;
    }

}
